﻿using System;

namespace JavaReflectionLib
{
    public class ActionHandle
    {

        public static int GetChildren(int nHandle, out string szChildrenName, int maxLength)
        {
            int result = -1;
            szChildrenName = "";
           
            windowTitle = Utilities.GetWindowTitle(nHandle, maxLength);
            port = Utilities.GetPortToSendRequest(windowTitle);
            System.Diagnostics.Debug.Write("port: " + port);
            if (port != -1)
            {
                // send msg to agent
                int res = Communication.sendMessage(port, windowTitle, Const.GET_CHILDREN);
                //if (res != -1)
                //{
                    // read result
                    szChildrenName = Utilities.ReadResult(Const.GET_CHILDREN);
                    if (szChildrenName.Length==0)
                    {
                        szChildrenName = "no content";
                    }
                    result = 0;
                //}
            }
            
            //szChildrenName = "Hello baby!" + nHandle.ToString() + maxLength.ToString();
            return result;
        }

        public static int GetSupportedProperty(string szControlName, out string szProperties, int maxLength)
        {
            szProperties = "a;b;c" + szControlName + " " + maxLength.ToString();
            return 0;
        }

        public static int GetProperty(string szControlName, string szPropertyName, out string szPropertyValue, int maxLength)
        {
            szPropertyValue = "yes " + szControlName +" " + szPropertyName + " " + maxLength.ToString();
            return 0;
        }

        public static int port { get; set; }
        public static string windowTitle { get; set; }
    }
}
